package com.example.govpn;

import static goclient.Goclient.newTextWebsocketMessage;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import goclient.Goclient;
import goclient.HTTPClient;
import goclient.Response;
import goclient.WebsocketClient;
import goclient.WebsocketConn;
import goclient.WebsocketMessage;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        HTTPClient client = Goclient.newHTTPClient();
        WebsocketClient wsClient = Goclient.newWebsocketClient();
        try {
            Response res = client.get("http://192.168.1.6:9200/");
            Log.d("GoClient", res.getStatus());
            Log.d("GoClient", res.getContentType());
            Log.d("GoClient", String.valueOf(res.getContentLength()));
            Log.d("GoClient", res.getHeader().string());
            Log.d("GoClient", res.readAsText());

            WebsocketConn ws = wsClient.dial("ws://192.168.1.6:9200/ws");
            ws.send(newTextWebsocketMessage("hello"));
            WebsocketMessage wm = ws.recv();
            Log.d("GoClient", new String(wm.getData()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}